Component({
    properties: {
        storageName: {
            type: String,
            value: "searchHistory"
        },
        showHistory: {
            type: Boolean,
            value: !1
        }
    },
    data: {
        searchHistoryList: [],
        showFlag: !1,
        loadShow: !1
    },
    lifetimes: {
        attached: function() {
            console.log(this.properties.storageName, "1212"), this.initKeywords(), this.showHistory();
        }
    },
    methods: {
        showHistory: function() {
            this.data.searchHistoryList.length > 0 && this.setData({
                showFlag: !0
            });
        },
        initKeywords: function() {
            try {
                var t = wx.getStorageSync(this.data.storageName);
                t ? this.setData({
                    searchHistoryList: JSON.parse(t)
                }) : wx.setStorageSync(this.data.storageName, "[]");
            } catch (t) {
                console.log(t);
            }
        },
        clearHistoryItems: function() {
            try {
                this.triggerEvent("popTag"), wx.removeStorageSync(this.data.storageName), this.setData({
                    searchHistoryList: [],
                    showFlag: !1
                });
            } catch (t) {
                console.log(t);
            }
        },
        popHistoryItems: function(t) {
            try {
                var s = t.target.dataset.item, a = this.data.searchHistoryList, e = this.data.searchHistoryList.findIndex(function(t) {
                    return t.name == s;
                });
                "" !== s && e >= 0 && (a.splice(e, 1), this.triggerEvent("popTag"), this.setData({
                    searchHistoryList: a
                }), wx.setStorageSync(this.data.storageName, JSON.stringify(a)));
            } catch (t) {
                console.log(t);
            }
            return !1;
        },
        appendKeywords: function(t) {
            var s = !0;
            if (t && (t = t.trim(), this.data.searchHistoryList && this.data.searchHistoryList.length > 0 && this.data.searchHistoryList.forEach(function(a, e) {
                a.name !== t || (s = !1);
            }), s && "" !== t)) {
                var a = this.data.searchHistoryList;
                this.data.searchHistoryList.length >= 10 && a.pop();
                var e = Date.parse(new Date());
                a.unshift({
                    name: t,
                    key: e
                }), wx.setStorageSync(this.data.storageName, JSON.stringify(a)), this.setData({
                    searchHistoryList: a
                });
            }
        },
        clickTag: function(t) {
            var s = t.currentTarget.dataset.item;
            this.triggerEvent("clickTag", s);
        }
    }
});